package com.tairanchina.wiki.api.model.wiki.content;

import com.tairanchina.wiki.api.TextBuilder;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 周靖捷 on 2016/10/4.
 */
public class ProjectPage implements PageElement {

    String title; //标题

    String brief; //简介

    List<ProjectPageFragment> fragments = new ArrayList<ProjectPageFragment>(); //内容

    public List<ProjectPageFragment> getFragments() {
        return fragments;
    }

    public ProjectPage setFragments(List<ProjectPageFragment> fragments) {
        this.fragments = fragments;
        return this;
    }

    public ProjectPage addFragment(ProjectPageFragment fragment) {
        fragments.add(fragment);
        return this;
    }

    public String getTitle() {
        return title;
    }

    public ProjectPage setTitle(String title) {
        this.title = title;
        return this;
    }

    public String getBrief() {
        return brief;
    }

    public ProjectPage setBrief(String brief) {
        this.brief = brief;
        return this;
    }

    @Override
    public String toMarkdown() {
        TextBuilder tBuilder = new TextBuilder();
        tBuilder.writeln(title)
                .writeln("====")
                .writeln(brief).nextLine();
        if (fragments != null)
            for (ProjectPageFragment fragment : fragments) {
                tBuilder.writeln(fragment.toMarkdown());
                tBuilder.nextLine();
            }
        return tBuilder.build();
    }

    public static void main(String[] args) {
        ProjectPage page = new ProjectPage();
        page.setTitle("测试");
        page.setBrief("测试描述");
        page.addFragment(new SimplePointListPageFragment().setTitle("测试内容1").addPointListContent("列表1").addPointListContent("列表2"));
        System.out.println(page.toMarkdown());
    }
}
